import apiMod from '@/apiMod/index'
import { getStore } from '@/utils/store'

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	labelWidth: '90px',
	column: [
		{
			label: '任务名称',
			prop: 'taskName',
			type: 'text',
			span: 8,
		},

		{
			label: '隐患评估表',
			prop: 'tableTemplateId',
			propName: 'tableTemplateName',
			type: 'remoteSelect',
			api: 'view_tableTemplate_page',
			filterKey: 'id',
			filterLabel: 'templateName',
			multiple: false,
			paramsObj: {
				type: 6,
			},
			span: 8,
		},
		{
			label: '评估第三方',
			prop: 'evaluateThirdPartiesCreditCode',
			propName: 'evaluateThirdParties',
			type: 'remoteSelect',
			api: 'view_dpServiceOrgBase_page',
			filterKey: 'creditCode',
			filterLabel: 'organizationName',
			multiple: false,
			changeField: true,
			viewDisplay: false,
			span: 8,
		},
		{
			label: '评估时间',
			prop: 'evaluateTimeBetween',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			type: 'dateBetween',
			span: 8,
		},
		{
			label: '有效时间',
			prop: 'effectiveStartTimeBetween',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			type: 'dateBetween',
			span: 8,
		},
		{
			label: '评估结果',
			prop: 'result',
			type: 'input',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '任务名称', prop: 'taskName' },
		{ label: '隐患评估表', prop: 'tableTemplateName' },
		{ label: '评估第三方', prop: 'evaluateThirdParties' },
		{ label: '评估时间', prop: 'evaluateTime' },
		{
			label: '评估状态',
			prop: 'status',
			custome: 'tag',
			dicData: [
				{
					label: '未评估',
					value: 0,
					type: 'danger',
				},
				{
					label: '已评估',
					value: 1,
					type: 'success',
				},
			],
		},
		{
			label: '评估结果',
			prop: 'result',
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_pbHazardAssessment_page',
	edit: 'view_pbHazardAssessment_edit',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '隐患评估任务',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '创建任务',
	tipLabel: 'taskName',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '评估',
			type: 'primary',
			operate: 'access',
			auth: auth.edit,
			text: true,
			show: true,
			condition: '(row)=>{return row.status==0}',
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	operateFormate: async (row, type) => {
		return new Promise((resolve, reject) => {
			if (type == 'access') {
				apiMod.view_pbHazardAssessmentTask_judge(row.taskId).then(() => {
					resolve(row)
				})
				return
			}
			resolve(row)
		})
	},
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			resolve(form)
		})
	},
	beforeOnLoadFormate: async (query) => {
		let userInfo = getStore('userInfo') || {}
		return new Promise((resolve, reject) => {
			if (userInfo.classifyId == 5) {
				query.evaluateThirdPartiesCreditCode = userInfo.organizationId
			} else {
				query.creditCode = userInfo.organizationId == 1 ? undefined : userInfo.organizationId
			}
			resolve(query)
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(arr)
		})
	},
	dialogConfig: {
		width: '65%',
	},
	searchConfig,
	tableConfig,
}
